<template>
  <div class='workReportPersonOverview'>
    <div class='workReportPersonOverview-left'>
      <a-table
        ref='table'
        size='small'
        bordered
        rowKey='id'
        :columns='columns'
        :scroll='{x:true,y:250}'
        :dataSource='dataSource'
        :pagination='false'
        :loading='loading'
        class='j-table-force-nowrap'
      >
      </a-table>
    </div>
    <div class='workReportPersonOverview-right'>
      <div id='person-chart'></div>
    </div>
  </div>
</template>

<script>
import { getAction } from '@api/manage'

export default {
  name: 'WorkReportPersonOverview',
  description: '报工统计-人员页面',
  data() {
    return {
      columns: [
        {
          title: '姓名',
          align: 'center',
          dataIndex: 'reprotPersion',
          width:200,
        },
        {
          title: '报工天数',
          align: 'center',
          dataIndex: 'countNum',
        }
      ],
      url: {
        statisticsByPerson: '/pm/hfPmWorkReports/statisticsByPerson'
      },
      personType: [],
      dataSource: [],
      loading: false,
    }
  },
  methods: {
    loadData(projectSortName) {
      getAction(this.url.statisticsByPerson, { projectSortName }).then(res => {
        if (res.success) {
          this.renderChart(res.result)
          this.dataSource = res.result.dataSource || res.result
          let personType = []
          res.result.person.forEach((item, index) => {
            personType.push([item, res.result.countNum[index]])
          })
        }
      })
    },
    renderChart(item) {
      let myCharts = this.$echarts.init(document.getElementById('person-chart'))
      let option = {
        // color:['#409eff'],
        xAxis: {
          type: 'category',
          axisLabel: {
            interval: 0,
            rotate: 45,
            fontSize: 14,
            color: '#000'
          },
          data: item.person
        },
        tooltip: {
          trigger: 'axis',
          textStyle: {
            fontSize: 14
          },
          axisPointer: { type: 'shadow' }
        },
        grid: {
          top: 30,
          right: 0,
          left: 80
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: item.countNum,
            type: 'bar',
            label:{
              show:true,
              position:'top',
              color: 'black'
            }
          },

        ]
      }
      myCharts.setOption(option)
      window.onresize = () => {
        myCharts.resize()
      }
    }
  }
}
</script>

<style scoped lang='less'>
.workReportPersonOverview {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;

  /deep/ &-left {
    width: 35%;
    height: 100%;
  }

  &-right {
    width: 65%;
    height: 100%;

    #person-chart {
      width: 100%;
      height: 230px
    }
  }
}
</style>